package com.opgea.crm.web.form;

import org.springframework.web.bind.annotation.SessionAttributes;

import com.opgea.crm.common.util.DateUtil;
import com.opgea.crm.domain.entities.Activity;
import com.opgea.crm.domain.entities.Employee;
import com.opgea.crm.domain.entities.Lead;
import com.opgea.crm.domain.entities.Opportunity;

@SessionAttributes
public class DynamicActivityForm {
	
		private long activityId;
		private String activityLeadId;
		
		private String subject;
		private String dueDate;
		private String duration;
		private String activityNotes;
		private String reminder;
		private String reminderDate;
		
		private String activityType;
		private long activityTypeId;
		
		private String priority;
		private long priorityId;
		
		private String status;
		private long statusId;
		
		private String activityStage;
		private long activityStageId;
		
		private String assignedTo;
		private long assignedToId;
		
		private String opportunity;
		private long opportunityId;		
		
		//Extra
		private String searchCriteria;
		private String criteriaValue;
		
		public DynamicActivityForm(){
			System.out.println("DynamicActivityForm DefaultConstructor : "+this.getClass().getName());
		}		
		
		public long getActivityId() {
			return activityId;
		}

		public void setActivityId(long activityId) {
			this.activityId = activityId;
		}

		public String getActivityLeadId() {
			return activityLeadId;
		}

		public void setActivityLeadId(String activityLeadId) {
			this.activityLeadId = activityLeadId;
		}

		public String getSubject() {
			return subject;
		}

		public void setSubject(String subject) {
			this.subject = subject;
		}

		public String getDueDate() {
			return dueDate;
		}

		public void setDueDate(String dueDate) {
			this.dueDate = dueDate;
		}

		public String getDuration() {
			return duration;
		}

		public void setDuration(String duration) {
			this.duration = duration;
		}

		public String getActivityNotes() {
			return activityNotes;
		}

		public void setActivityNotes(String activityNotes) {
			this.activityNotes = activityNotes;
		}

		public String getReminder() {
			return reminder;
		}

		public void setReminder(String reminder) {
			this.reminder = reminder;
		}

		public String getReminderDate() {
			return reminderDate;
		}

		public void setReminderDate(String reminderDate) {
			this.reminderDate = reminderDate;
		}

		public String getActivityType() {
			return activityType;
		}

		public void setActivityType(String activityType) {
			this.activityType = activityType;
		}

		public long getActivityTypeId() {
			return activityTypeId;
		}

		public void setActivityTypeId(long activityTypeId) {
			this.activityTypeId = activityTypeId;
		}

		public String getPriority() {
			return priority;
		}

		public void setPriority(String priority) {
			this.priority = priority;
		}

		public long getPriorityId() {
			return priorityId;
		}

		public void setPriorityId(long priorityId) {
			this.priorityId = priorityId;
		}

		public String getStatus() {
			return status;
		}

		public void setStatus(String status) {
			this.status = status;
		}

		public long getStatusId() {
			return statusId;
		}

		public void setStatusId(long statusId) {
			this.statusId = statusId;
		}

		public String getActivityStage() {
			return activityStage;
		}

		public void setActivityStage(String activityStage) {
			this.activityStage = activityStage;
		}

		public long getActivityStageId() {
			return activityStageId;
		}

		public void setActivityStageId(long activityStageId) {
			this.activityStageId = activityStageId;
		}

		public String getAssignedTo() {
			return assignedTo;
		}

		public void setAssignedTo(String assignedTo) {
			this.assignedTo = assignedTo;
		}

		public long getAssignedToId() {
			return assignedToId;
		}

		public void setAssignedToId(long assignedToId) {
			this.assignedToId = assignedToId;
		}

		public String getOpportunity() {
			return opportunity;
		}

		public void setOpportunity(String opportunity) {
			this.opportunity = opportunity;
		}

		public long getOpportunityId() {
			return opportunityId;
		}

		public void setOpportunityId(long opportunityId) {
			this.opportunityId = opportunityId;
		}

		public String getSearchCriteria() {
			return searchCriteria;
		}

		public void setSearchCriteria(String searchCriteria) {
			this.searchCriteria = searchCriteria;
		}

		public String getCriteriaValue() {
			return criteriaValue;
		}

		public void setCriteriaValue(String criteriaValue) {
			this.criteriaValue = criteriaValue;
		}

		public DynamicActivityForm(Activity activity){
			
			System.out.println("DynamicActivityForm : "+this.getClass().getName());
			Employee assignedTo = activity.getAssignTo();
			Opportunity opportunity = activity.getOpportunity();
			Lead lead = activity.getLead();
			
			if(lead != null){
				this.setActivityId(activity.getId());
				this.setActivityLeadId(String.valueOf(lead.getId()));
			}
			if(activity.getActivityStage() != null){
				this.setActivityStage(activity.getActivityStage().getFieldValue());
				this.setActivityStageId(activity.getActivityStage().getId());
			}
			if(activity.getActivityStatus() != null){
				this.setStatus(activity.getActivityStatus().getFieldValue());
				this.setStatusId(activity.getActivityStatus().getId());
			}
			if(activity.getActivityType() != null){
				this.setActivityType(activity.getActivityType().getFieldValue());
				this.setActivityTypeId(activity.getActivityType().getId());
			}
			if(activity.getPriority() != null){
				this.setPriority(activity.getPriority().getFieldValue());
				this.setPriorityId(activity.getPriority().getId());
			}
			if(opportunity != null){
				this.setOpportunity(opportunity.getOpportunityTitle());
				this.setOpportunityId(opportunity.getId());
			}
			if(assignedTo != null){
				this.setAssignedTo(assignedTo.getFirstName());
				this.setAssignedToId(new Long(assignedTo.getId()));
			}
			
			this.setDuration(String.valueOf(activity.getDuration()));
			this.setActivityNotes(activity.getNote());
			this.setSubject(activity.getSubject());
			this.setDueDate(DateUtil.dateToString(activity.getScheduledDate()));
			this.setReminderDate(DateUtil.dateToString(activity.getReminderDate()));
			
		}

		@Override
		public String toString() {
			return "DynamicActivityForm [activityId=" + activityId
					+ ", activityType=" + activityType
					+ ", activityTypeId=" + activityTypeId
					+ "]";
		}
		
		
}
